<?php

namespace addon\lian\event;

use addon\lian\model\core\settle\CoreLianSettleService;
use addon\lian\model\sqlmodel\LianRewardModel;
use think\facade\Db;
use think\facade\Log;

/**
 * 启动活动
 */
class CronLianSettle
{

    public function handle($params = [])
    {
        Log::info('=========链动2+1结算=========');
        // 查询所有未结算的股东分红
        try {
            $list = (new LianRewardModel())->where('status', '=', 1)->select();
            

            if(!$list->isEmpty()){
                $ids = array_column($list->toArray(), 'id');
                (new CoreLianSettleService())->handleQueue($ids);
            }

            Log::write('链动奖励结算发放任务执行成功');
            return true;
        } catch (\Exception $e) {
            Log::write('链动奖励结算发放任务执行失败: ' . $e->getMessage());
            return false;
        }
    }
}